<template>
	<view class="address">
		<!-- 无地址 -->
		<view class="noaddress" v-if="JSON.stringify(address) ==='{}'">
			<button type="primary" @click="getAddress" size="mini">请选择收货地址+</button>
		</view>
		<!-- 有地址 -->
		<view class="hasaddress" v-else @click="getAddress">
			<view class="top">
				<view class="left">
					收货人：{{address.userName}}
				</view>
				<view class="right">
					电话：{{address.telNumber}}
				</view>
			</view>
			<view class="bottom">
				收货地址：{{fullAddress}}
			</view>
		</view>
		<image class="img" src="../../static/tabs/cart_border@2x.png" mode="widthFix"></image>
	</view>
</template>



<script>
	import {
		mapState,
		mapGetters,
		mapMutations
	} from 'vuex'
	import {
		computed
	} from "vue";
	export default {
		name: "my-address",
		computed: {
			...mapState('address', ['address']),
			...mapGetters('address', ['fullAddress'])
		},
		data() {
			return {

			};
		},
		methods: {
			...mapMutations('address', ['setAddress']),
			async getAddress() {
				console.log(11);
				let res = await uni.chooseAddress()
				console.log(res);
				this.setAddress(res[1])
			}
		}
	}
</script>

<style lang="scss">
	.address {
		height: 200rpx;
		margin-bottom: 10rpx;

		.noaddress {
			height: 200rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.hasaddress {
			font-size: 12px;
			padding: 20rpx;
			line-height: 60rpx;

			.top {
				display: flex;
				justify-content: space-between;

				.left {}

				.right {}
			}

			.bottom {}
		}

		.img {
			display: block;
			width: 100%;
		}
	}
</style>
